package com.kly.user.task.service;

import cn.hutool.core.collection.CollUtil;
import com.kly.user.db.dao.UserDao;
import com.kly.user.db.entity.UserEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class CommonUtilityService {

    @Resource
    UserDao userDao;

    public Map<String, UserEntity> getUserList(String... userCodes) {
        Map<String, Object> selectUsersParams = new HashMap<>();
        List<String> userCodeList = Arrays.asList(userCodes);
        selectUsersParams.put("list", userCodeList);
        List<UserEntity> userEntities = userDao.selectUsers(selectUsersParams);
        if (CollUtil.isNotEmpty(userEntities)&&userEntities.size()==userCodeList.size()) {
            return userEntities.stream()
                    .collect(Collectors.toMap(UserEntity::getUserCode, Function.identity()));
        }
        return null;
    }
}
